package fileTransfer;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;

import java.awt.dnd.DropTarget;
import java.awt.event.MouseAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.internal.runtime.Activator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.wb.swt.SWTResourceManager;

import com.laobiao.file_netty_lib.netty.client.FileClient;
import com.laobiao.file_netty_lib.netty.client.handler.fileList.FileDetail;
import com.laobiao.file_netty_lib.netty.client.handler.fileList.FileDetail.FileType;

import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;

public class FileTransfer {

	protected Shell shell;
	private Text site;
	private Text port;
	protected FileClient client;
	private String path = "";
	private String filePath = "";
	private String fileName = "";
	private Text savepath;
	private String tranpath = "";
	private Text logtext;
	private TreeItem treeNode = null;
	private String dowmPath = "";
	private String dirPath = "";

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			FileTransfer window = new FileTransfer();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents(display);
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents(Display display) {
		shell = new Shell(SWT.MIN);
		shell.setSize(800, 500);
		shell.setText("SWT Application");
		shell.setLayout(null);

		CLabel lblNewLabel = new CLabel(shell, SWT.NONE);
		lblNewLabel.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		lblNewLabel.setBounds(10, 16, 80, 33);
		lblNewLabel.setText("服务地址:");

		site = new Text(shell, SWT.BORDER);
		site.setBounds(109, 17, 147, 32);
		site.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		site.setText("127.0.0.1");

		port = new Text(shell, SWT.BORDER);
		port.setBounds(350, 17, 96, 32);
		port.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		port.setText("10010");

		org.eclipse.swt.widgets.List listItem = new org.eclipse.swt.widgets.List(shell, SWT.V_SCROLL);
		listItem.setLayoutData(new RowData(561, 320));
		listItem.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		listItem.setBounds(223, 71, 561, 320);

		

		Button btnNewButton = new Button(shell, SWT.NONE);
		btnNewButton.setBounds(479, 16, 123, 33);

		Tree tree = new Tree(shell, SWT.BORDER);
		tree.setToolTipText("");
		tree.setBounds(10, 71, 207, 320);
		btnNewButton.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		btnNewButton.setText("连接");

		CLabel lblNewLabel_2 = new CLabel(shell, SWT.NONE);
		lblNewLabel_2.setAlignment(SWT.CENTER);
		lblNewLabel_2.setBounds(273, 16, 71, 32);
		lblNewLabel_2.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		lblNewLabel_2.setText("端口:");

		savepath = new Text(shell, SWT.BORDER);
		savepath.setToolTipText("/xxx/xxx/123.txt");
		savepath.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		savepath.setBounds(96, 410, 195, 35);

		CLabel lblNewLabel_1 = new CLabel(shell, SWT.NONE);
		lblNewLabel_1.setBounds(10, 409, 80, 36);
		lblNewLabel_1.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		lblNewLabel_1.setText("存储地址:");

		Button btnNewButton_1 = new Button(shell, SWT.NONE);
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				// 新建文件对话框，并设置为打开的方式
				FileDialog filedlg = new FileDialog(shell, SWT.OPEN);
				// 设置文件对话框的标题
				filedlg.setText("文件选择");
				// 设置初始路径
				filedlg.setFilterPath("SystemRoot");
				// 打开文件对话框，返回选中文件的绝对路径
				String selected = filedlg.open();
				if(selected!=null) {
					tranpath = selected;
					savepath.append("/" + selected.substring(selected.lastIndexOf("\\") + 1));
				}				
				System.out.println("您选中的文件路径为：" + selected);
			}
		});
		btnNewButton_1.setBounds(339, 412, 80, 33);
		btnNewButton_1.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		btnNewButton_1.setText("文件选择");

		Button button = new Button(shell, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				// String substring = tranpath.substring(tranpath.lastIndexOf("/"),
				// tranpath.length());
				String text = savepath.getText();

				logtext.append(text.substring(text.lastIndexOf("/") + 1) + "开始上传...\n");
				Thread thread = new Thread() {
					@Override
					public void run() {
						try {
							client.uploadFile(new File(tranpath), text);
						} catch (Exception e2) {
							// TODO: handle exception
						}
						display.syncExec(new Runnable() {
							@Override
							public void run() {
								logtext.append(text.substring(text.lastIndexOf("/") + 1) + "上传完成!\n");
							}
						});
					}
				};
				thread.start();

				String substring = "root/" + savepath.getText().substring(1);
				String[] split = substring.split("/");
				TreeItem[] items = null;
				TreeItem ite = null;

				for (int i = 0; i < split.length; i++) {
					if (i == 0) {
						items = tree.getItems();
					} else {
						items = ite.getItems();
					}
					TreeItem it = getItem(items, split[i]);
					if (it != null) {
						ite = it;
					} else {

						if (i != split.length - 1) {
							TreeItem tmp = null;
							if (i == 0) {
								tmp = new TreeItem(tree, SWT.NONE);
							} else {
								tmp = new TreeItem(ite, SWT.NONE);
							}

							tmp.setExpanded(true);
							tmp.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
							tmp.setData("type", "dir");
							tmp.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
							tmp.setImage(new Image(shell.getDisplay(), "lib/wj.png"));
							tmp.setText(split[i]);
							ite = tmp;
						} else {
							ite = null;
							listItem.add(split[i]);
							/*
							 * tmp.setData("type", "file");
							 * tmp.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12,
							 * SWT.NORMAL)); tmp.setImage(new Image(shell.getDisplay(), "lib/wj1.png"));
							 * tmp.setText(split[i]);
							 */
						}

					}

				}

			}
		});
		button.setBounds(456, 410, 89, 36);
		button.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
		button.setText("上传");
		button.setEnabled(false);

		logtext = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
		logtext.setTopIndex(4);
		logtext.setBounds(571, 397, 213, 64);

		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String siteValue = site.getText();

				String portValue = port.getText();
				client = new FileClient(siteValue, Integer.parseInt(portValue), null);
				client.setDefaultTimeoutSeconde(100);

				if (client.status) {
					btnNewButton.setEnabled(false);
					logtext.append("服务器连接成功!\n");
					button.setEnabled(true);
					TreeItem trtmDs = new TreeItem(tree, SWT.NONE);
					trtmDs.setExpanded(true);
					trtmDs.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
					trtmDs.setData("type", "dir");
					trtmDs.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
					trtmDs.setImage(new Image(shell.getDisplay(), "./lib/wj.png"));
					trtmDs.setText("root");

				} else {
					logtext.append("服务器连接失败!\n");
					button.setEnabled(false);
				}

			}
		});

		tree.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				treeNode = null;
				TreeItem selectItem = (TreeItem) e.item;
				String data = selectItem.getData("type").toString();
				fileName = selectItem.getText();
				TreeItem[] items = selectItem.getItems();
				List<String> itemData = new ArrayList<String>();
				List<String> list = new ArrayList<String>();
				for (TreeItem treeItem : items) {
					list.add(treeItem.getText());
					if (!treeItem.getData("type").toString().equals("dir")) {
						itemData.add(treeItem.getText());
					}
				}
				if (data.equals("dir")) {
					treeNode = selectItem;
					listItem.removeAll();
					path = "";
					getName(selectItem);
					if (path.equals("")) {
						savepath.setText("/");
					} else {
						savepath.setText(path);
					}

					List<FileDetail> details = client.getFileList(path);

					for (FileDetail fileDetail : details) {

						if (list.contains(fileDetail.getFileName())) {
							continue;
						}

						if (fileDetail.getFileType().equals(FileType.DIR)) {
							TreeItem trtmDs1 = new TreeItem(selectItem, SWT.NONE);
							trtmDs1.setExpanded(true);
							trtmDs1.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
							trtmDs1.setData("type", "dir");
							trtmDs1.setImage(new Image(shell.getDisplay(), "lib/wj.png"));
							trtmDs1.setText(fileDetail.getFileName());
						} else {

							itemData.add(fileDetail.getFileName());
							/*
							 * trtmDs1.setData("type", "file");
							 * trtmDs1.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12,
							 * SWT.NORMAL)); trtmDs1.setImage(new Image(shell.getDisplay(), "lib/wj1.png"));
							 * trtmDs1.setText(fileDetail.getFileName());
							 */
						}
					}
					listItem.setItems(itemData.toArray(new String[itemData.size()]));

				} else {
					listItem.removeAll();
					filePath = "";
					path = "";
					getName(selectItem);
					filePath = path;
				}

			}
		});

		tree.addMouseListener(new MouseListener() {

			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseDown(MouseEvent e) {
				Menu menu = new Menu(tree);
				MenuItem newItem = new MenuItem(menu, SWT.PUSH);
				newItem.setText("创建目录");
				MenuItem newItem1 = new MenuItem(menu, SWT.PUSH);
				newItem1.setText("删除");
				tree.setMenu(menu);
				newItem.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event event) {
						InputDialog inputDialog = new InputDialog(shell,"新建目录","请输入目录名","",null);
						if(inputDialog.open() == InputDialog.OK){
							Thread thread = new Thread() {

								@Override
								public void run() {
									try {
										if (!path.equals("")) {
											if(!inputDialog.getValue().equals("")) {
												client.mkdir(path+"/"+inputDialog.getValue());
											}
										}

									} catch (Exception e2) { // TODO: handle exception

									}
								}
							};
							thread.start();
							if(!inputDialog.getValue().equals("")) {
								TreeItem trtmDs = new TreeItem(treeNode, SWT.NONE);
								trtmDs.setExpanded(true);
								trtmDs.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
								trtmDs.setData("type", "dir");
								trtmDs.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
								trtmDs.setImage(new Image(shell.getDisplay(), "./lib/wj.png"));
								trtmDs.setText(inputDialog.getValue());	
							}							
							
						}
						/*
						 * // 新建文件夹（目录）对话框 DirectoryDialog folderdlg = new DirectoryDialog(shell); //
						 * 设置文件对话框的标题 folderdlg.setText("文件选择"); // 设置初始路径
						 * folderdlg.setFilterPath("SystemDrive"); // 设置对话框提示文本信息
						 * folderdlg.setMessage("请选择文件存放位置"); // 打开文件对话框，返回选中文件夹目录 String selecteddir =
						 * folderdlg.open(); if (selecteddir == null) { return; } else {
						 * System.out.println("您选中的文件夹目录为：" + selecteddir); } //
						 * client.downloadFile(filePath, selecteddir + "/" + fileName);
						 * 
						 * logtext.append(fileName + "开始下载...\n"); Thread thread = new Thread() {
						 * 
						 * @Override public void run() { try { client.downloadFile(filePath, selecteddir
						 * + "\\" + fileName); System.out.println(filePath + "```````````````" +
						 * selecteddir + "\\" + fileName); } catch (Exception e2) { // TODO: handle
						 * exception
						 * 
						 * } display.syncExec(new Runnable() {
						 * 
						 * @Override public void run() {
						 * 
						 * logtext.append(fileName + "下载完成!\n"); } }); } }; thread.start();
						 */

					}
				});
				newItem1.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event event) {

						Thread thread = new Thread() {

							@Override
							public void run() {
								try {
									if (!path.equals("")) {
										client.fileDelete(path);
										System.out.println(path);
									}

								} catch (Exception e2) { // TODO: handle exception

								}
								display.syncExec(new Runnable() {

									@Override
									public void run() {

										logtext.append(path + "删除完成!\n");
									}
								});
							}
						};
						thread.start();
						treeNode.dispose();
						// treeNode.removeAll();

					}
				});
			}

			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub

			}
		});

		shell.addListener(SWT.Close, new Listener() {
			public void handleEvent(Event event) {
				if (client != null) {
					client.close();
				}

			}
		});

		org.eclipse.swt.dnd.DropTarget dropTarget = new org.eclipse.swt.dnd.DropTarget(listItem, DND.DROP_MOVE);
		Transfer[] transfer = new Transfer[] { org.eclipse.swt.dnd.FileTransfer.getInstance() };
		dropTarget.setTransfer(transfer);
		
		/*
		 * DragSource dragSource = new DragSource(listItem, DND.DROP_MOVE);
		 * dragSource.setTransfer(new Transfer[]
		 * {org.eclipse.swt.dnd.FileTransfer.getInstance()});
		 * dragSource.addDragListener(new DragSourceAdapter() { public void
		 * dragSetData(DragSourceEvent event) { event.doit = true; event.data =
		 * listItem.getSelection(); System.out.println(event.data); }
		 * 
		 * @Override public void dragStart(DragSourceEvent event) {
		 * 
		 * //event.data = listItem.getSelection();
		 * System.out.println(event.data+"start---------"); }
		 * 
		 * @Override public void dragFinished(DragSourceEvent event) { event. //String
		 * dsa = (String)event.data; //event.data = listItem.getSelection();
		 * System.out.println(event.data+"end---------"); } });
		 */
		dropTarget.addDropListener(new DropTargetAdapter() {
			@Override
			public void drop(DropTargetEvent event) {
				String[] files = (String[]) event.data;
				
				path = "";
				if (treeNode == null) {
					MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
					mb.setText("提示！");
					mb.setMessage("请重新选择文件夹，root不能存放文件");
					mb.open();
				} else {
					getName(treeNode);
					
					String text = path + "/";
					String[] tlist= new String[files.length];
					for (int i = 0; i < files.length; i++) {
						tlist[i] = files[i].substring(files[i].lastIndexOf("\\") + 1);
					}
					MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.CANCEL);
					messageBox.setText("提示");
					messageBox.setMessage("文件将上传到：" + text);
					if (messageBox.open() == SWT.OK) {
						System.err.println("==========" + files[0]);
						// 文件上传												
						logtext.append(Arrays.toString(tlist) + "开始上传...\n");
						Thread thread = new Thread() {
							@Override
							public void run() {
								try {
									for (String file : files) {
										String fileName = file.substring(file.lastIndexOf("\\") + 1);
										client.uploadFile(new File(file), text+fileName);
									}
									
								} catch (Exception e2) {
									// TODO: handle exception
								}
								display.syncExec(new Runnable() {
									@Override
									public void run() {
										logtext.append(Arrays.toString(tlist) + "上传完成!\n");
									}
								});
							}
						};
						thread.start();
						for (int i = 0; i < tlist.length; i++) {
							listItem.add(tlist[i]);
							String substring = "root/" + text.substring(1)+tlist[i];
							String[] split = substring.split("/");
							TreeItem[] items = null;
							TreeItem ite = null;

							for (int i1 = 0; i1 < split.length; i1++) {
								if (i1 == 0) {
									items = tree.getItems();
								} else {
									items = ite.getItems();
								}
								TreeItem it = getItem(items, split[i1]);
								if (it != null) {
									ite = it;
								} else {

									if (i1 != split.length - 1) {
										TreeItem tmp = null;
										if (i1 == 0) {
											tmp = new TreeItem(tree, SWT.NONE);
										} else {
											tmp = new TreeItem(ite, SWT.NONE);
										}

										tmp.setExpanded(true);
										tmp.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
										tmp.setData("type", "dir");
										tmp.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12, SWT.NORMAL));
										tmp.setImage(new Image(shell.getDisplay(), "lib/wj.png"));
										tmp.setText(split[i1]);
										ite = tmp;
									} else {
										ite = null;
										/*
										 * tmp.setData("type", "file");
										 * tmp.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 12,
										 * SWT.NORMAL)); tmp.setImage(new Image(shell.getDisplay(), "lib/wj1.png"));
										 * tmp.setText(split[i]);
										 */
									}

								}

							}
						}
						
					}
				}

			}

		});

		// listItem右键事件
		listItem.addMouseListener(new MouseListener() {

			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseDown(MouseEvent e) {

				String[] selection = listItem.getSelection();

				
					Menu menu = new Menu(listItem);
					MenuItem newItem = new MenuItem(menu, SWT.PUSH);
					newItem.setText("下载");
					MenuItem newItem1 = new MenuItem(menu, SWT.PUSH);
					newItem1.setText("删除");
					listItem.setMenu(menu);
					
					newItem.addListener(SWT.Selection, new Listener() {
						public void handleEvent(Event event) {
							// 新建文件夹（目录）对话框
							DirectoryDialog folderdlg = new DirectoryDialog(shell);
							// 设置文件对话框的标题
							folderdlg.setText("文件选择");
							// 设置初始路径
							folderdlg.setFilterPath("SystemDrive");
							// 设置对话框提示文本信息
							folderdlg.setMessage("请选择文件存放位置");
							// 打开文件对话框，返回选中文件夹目录
							String selecteddir = folderdlg.open();
							if (selecteddir == null) {
								return;
							} else {
								System.out.println("您选中的文件夹目录为：" + selecteddir);
							}
							// client.downloadFile(filePath, selecteddir + "/" + fileName);
							dowmPath = "";
							if (treeNode != null) {
								path = "";
								getName(treeNode);
								dowmPath = path + "/" ;

							} else {
								dowmPath = "/";
							}
							logtext.append(Arrays.toString(selection) + "开始下载...\n");
							if (selection.length <= 0) {
								MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
								mb.setText("提示！");
								mb.setMessage("请选择要下载的文件");
								mb.open();
							} else {
							Thread thread = new Thread() {

								@Override
								public void run() {
									try {
										for (int j = 0; j < selection.length; j++) {

											client.downloadFile(dowmPath+selection[j], selecteddir + "\\" + selection[j]);
										}
										
										
									} catch (Exception e2) { // TODO: handle exception

									}
									display.syncExec(new Runnable() {

										@Override
										public void run() {

											logtext.append(Arrays.toString(selection) + "下载完成!\n");
										}
									});
								}
							};
							thread.start();
							}//

						}
					});
					newItem1.addListener(SWT.Selection, new Listener() {
						public void handleEvent(Event event) {

							dowmPath = "";
							if (treeNode != null) {
								path = "";
								getName(treeNode);
								dowmPath = path + "/";
							} else {
								dowmPath = "/";
							}
							logtext.append(Arrays.toString(selection)+"开始删除...\n");
							if (selection.length <= 0) {
								MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
								mb.setText("提示！");
								mb.setMessage("请选择要下载的文件");
								mb.open();
							} else {
							Thread thread = new Thread() {

								@Override
								public void run() {
									try {
										for (int j = 0; j < selection.length; j++) {

											client.fileDelete(dowmPath + selection[j]);
										}

									} catch (Exception e2) { // TODO: handle exception

									}
									display.syncExec(new Runnable() {

										@Override
										public void run() {

											logtext.append(Arrays.toString(selection)+"删除完成!\n");
										}
									});
								}
							};
							thread.start();
							for (int j = 0; j < selection.length; j++) {

								listItem.remove(selection[j]);
							}
							//
							}

						}
					});
				//}

			}

			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub

			}
		});
	}

	public void getName(TreeItem t) {

		if (!t.getText().equals("root")) {
			TreeItem parentItem = t.getParentItem();
			path = "/" + t.getText() + path;
			if (parentItem != null) {
				this.getName(parentItem);
			}
		}

	}

	public TreeItem getItem(TreeItem[] item, String name) {
		for (TreeItem treeItem : item) {
			if (treeItem.getText().equals(name)) {
				return treeItem;
			}
		}
		return null;
	}
}
